package zuk.clipvietfun.home;

import static zuk.clipvietfun.MPagerAdapter.MENU;

import java.util.ArrayList;
import java.util.List;

import zuk.clipvietfun.R;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
@SuppressLint("ValidFragment")
public class FragmentHome extends ListFragment {
	HomeAdapter adapter;
	Handler settab;
	List<HomeItem> myListItems = new ArrayList<HomeItem>();
	
	public FragmentHome(Handler settab) {
		this.settab = settab;
	}

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		adapter = new HomeAdapter(getActivity(), R.layout.homeitems, myListItems);
		setListAdapter(adapter);
		
		return inflater.inflate(R.layout.fragment_clip, null);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		myListItems.clear();
		for(int i = 1; i<MENU.length;i++){
			myListItems.add(new HomeItem("\t"+MENU[i]));
		}
		super.onActivityCreated(savedInstanceState);
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Message msg = new Message();
		msg.arg1 = position;
		settab.sendMessage(msg);
	}

	
}
